<%@page import="com.sina.sae.storage.SaeStorage"%>
<%@page import="com.sina.sae.util.SaeUserInfo"%>
<%@ page language="java" contentType="text/html; charset=GBK"
	pageEncoding="UTF-8"%>
<%@page import="java.util.Calendar"%>
<%@page import="com.jspsmart.upload.SmartUpload"%>
<%@page import="java.io.FileOutputStream"%>
<%
	String targetDirectory = SaeUserInfo.getSaeTmpPath();
	SaeStorage ss = new SaeStorage();
	long file_size_max = 8000000;
	//应保证在根目录中有此目录的存在
	String url = targetDirectory;
	SmartUpload mySmartUpload = new SmartUpload();
	//初始化
	mySmartUpload.initialize(pageContext);
	String saveurl = "";
	String imageName = "";
	//只允许上载此类文件
	try {
		mySmartUpload.setAllowedFilesList("jpg,gif,JPG,GIF");
		//上载文件 
		mySmartUpload.upload();
	} catch (Exception e) {
		out.println("<SCRIPT language=\"javascript\">");
		out.println("alert(\"只允许上传.jpg和.gif类型图片文件\");");
		out.println("window.location=\"user_form.jsp;\"");
		out.println("</SCRIPT>");
	}
	try {
		com.jspsmart.upload.File myFile = mySmartUpload.getFiles()
				.getFile(0);

		//取得后缀名
		String ext = myFile.getFileExt();
		//取得文件的大小
		int file_size = myFile.getSize();

		if (file_size < file_size_max) {
			//更改文件名，取得当前上传时间的毫秒数值
			Calendar calendar = Calendar.getInstance();
			String filename = String
					.valueOf(calendar.getTimeInMillis());
			saveurl = targetDirectory;
			//保存路径
			saveurl += "/"+filename + "." + ext;
			out.println(saveurl);
			myFile.saveAs(saveurl, mySmartUpload.SAVE_PHYSICAL);
			//上传完成，开始生成缩略图  

		} else {
			out.println("<SCRIPT language=\"javascript\">");
			out.println("alert(\"上传文件大小不能超过\" + (file_size_max / 1000) + \"K\");");
			out.println("window.location=\"user_form.jsp;\"");
			out.println("</SCRIPT>");
		}
		ss.upload("hugetechstorage", saveurl, "image/test.jpg");
		java.io.File file = new java.io.File(saveurl);
		file.delete();
	} catch (Exception e) {
		e.toString();
	}

	
%>

